﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.Framework.GC
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Destructor cLasses
                DesctructorClass dc1 = new DesctructorClass("dc1"); // dc1 (stack) ---> dc1 (Heap)
                DesctructorClass dc2 = dc1; // dc2 (stack) ---> dc2 (Heap)
                DesctructorClass dc3 = new DesctructorClass("dc3"); // dc3 (stack) ----> dc3 (Heap)
                
                // Disposable classes                
                DisposableClass dp1 = new DisposableClass("dp1"); // dp1 (stack) ---> dp1 (Heap)
                DisposableClass dp2 = dp1; // dc2 (stack) ---> dp1 (Heap)
                DisposableClass dp3 = new DisposableClass("dp3"); // dp3 (stack) ----> dp3 (Heap)

                dc1 = null;
                Console.WriteLine(dc2.ToString());
                dc3 = null;

                System.GC.Collect();

                dp1.Dispose();
                dp3.Dispose();                
                dp2.Dispose();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.Read();
            }

        }
    }
}
